﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Inventory.DAL;

namespace Inventory.Test
{
    /// <summary>
    /// Summary description for MasterDataTest
    /// </summary>
    [TestClass]
    public class MasterDataTest
    {
        public MasterDataTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public int CountryID { get; set; }
        public int CityID { get; set; }
        public int CurrencyID { get; set; }

        [TestMethod]
        public void CountryInsertTest()
        {
            var entities = new InventoryEntities();
            var country = new Country();
            country.Name = "UnitTest Country";

            entities.AddToCountry(country);

            entities.SaveChanges();
            CountryID = country.ID;
            Assert.IsTrue(country.ID > 0);
        }
        [TestMethod]
        public void CountryDeleteTest()
        {
            var entities = new InventoryEntities();
            int entityID = CountryID;
            var entity = entities.Country.Where(i => i.ID == entityID);
            entities.DeleteObject(entity);
        }
        [TestMethod]
        public void CityInsertTest()
        {
            var entities = new InventoryEntities();
            var city = new City();
            city.Name = "UnitTest City";

            entities.AddToCity(city);

            entities.SaveChanges();
            CityID = city.ID;
            Assert.IsTrue(city.ID > 0);
        }
        
        [TestMethod]
        public void CityDeleteTest()
        {
            var entities = new InventoryEntities();
            int entityID = CityID;
            var entity = entities.Country.Where(i => i.ID == entityID);
            entities.DeleteObject(entity);
        }
        [TestMethod]
        public void CurrencyInsertTest()
        {
            var entities = new InventoryEntities();
            var currency = new Currency();
            currency.Name = "UT";

            entities.AddToCurrency(currency);

            entities.SaveChanges();
            CurrencyID = currency.ID;
            Assert.IsTrue(currency.ID > 0);
        }
        [TestMethod]
        public void CurrencyDeleteTest()
        {
            var entities = new InventoryEntities();
            int entityID = CurrencyID;
            var entity = entities.Country.Where(i => i.ID == entityID);
            entities.DeleteObject(entity);
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestMethod1()
        {
            //
            // TODO: Add test logic	here
            //
        }
    }
}
